﻿@using Rework.CommerceHistory.Models
@using Nwazet.Commerce.Models
@using Orchard.ContentManagement

@{
    var items = (IList<dynamic>)Model.CommerceHistoryItems;
}
@if (!items.Any())
{
    <p>@T("You don't have any items you have ordered.")</p>
}
else { 
    <article class="commercehistory">
        
            <table>
                <thead>
                    <tr>
                        <td colspan="2">@T("Article")</td>
                        <td class="numeric">@T("Unit Price")</td>
                        <td class="numeric">@T("Quantity")</td>
                        <td class="numeric">@T("Total Price")</td>
                        <td class="numeric">@T("Order Processed")</td>
                        <td class="action"></td>
                    </tr>
                </thead>
                <tbody>
                    @for (var i = 0; i < items.Count; i++) {
                        var item = items[i];
                        var product = (IProduct) item.Product;
                        var contentItem = (IContent) item.Product;
                        var title = item.Title;
                        string imageUrl = (item.ProductImage != null ? item.ProductImage.Url : null);
                        var quantity = (int)item.Quantity;
                        var unitPrice = (double)item.Price;
                        var totalPrice = quantity*unitPrice;
                        var isPaymentConfirmed = (bool)item.IsPaymentConfirmed;
                        <tr>
                            @if (imageUrl != null) {
                                <td>
                                    <a href="@Url.ItemDisplayUrl(contentItem)" class="product-image-link"><img src="@Href(imageUrl)" alt="@title" class="product-image"/></a>
                                </td><td>
                                    <a href="@Url.ItemDisplayUrl(contentItem)" class="product-name">@title</a>
                                </td>
                            }
                            else {
                                <td colspan="2"><a href="@Url.ItemDisplayUrl(contentItem)">@title</a></td>
                            }
                            <td class="numeric">@unitPrice.ToString("c")</td>
                            <td class="numeric">
                                <input name="@string.Format("items[{0}].ProductId", i)" type="hidden" value="@product.Id" />
                                <input name="@string.Format("items[{0}].Quantity", i)" type="number" class="quantity" value="@quantity" />
                            </td>
                            <td class="numeric">@totalPrice.ToString("c")</td>
                            <td class="numeric">@isPaymentConfirmed.ToString()</td>
                        </tr>
                    }
            
                </tbody>
            </table>

    </article>
}